﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.DataAcsess.Interfaces;
using KCMS.DataAcsess.Entitys;

namespace KCMS.DataAcsess.Engine
{
    public class ProductManager:IProductManager
    {
        protected DataClassesDataContext db = new DataBaseConnect().DataBase;
        private DataManager<ProductEntity> dm = new DataManager<ProductEntity>();
        public ProductEntity getById(Guid id)
        {
            return (from t in db.GetTable<ProductEntity>()
                    where t.Id.Equals(id)
                    select t).SingleOrDefault();
        }
        public IEnumerable<ProductEntity> getAll()
        {
           // var model = dm.getAll().Concat(dm.getAll()).Concat(dm.getAll()).Concat(dm.getAll()).Concat(dm.getAll());
            return dm.getAll();
        }

        public void delete(Guid id)
        {
            //var model = getById(id);
            //db.GetTable<ProductEntity>().DeleteOnSubmit(model);
            //db.SubmitChanges();
            dm.delete(id);
        }

        public void update(ProductEntity product)
        {
            db = new DataBaseConnect().DataBase;
            var old = getById(product.Id);
            old.CopyPropyties(product);
            db.SubmitChanges();
        }

        public void save(ProductEntity product)
        {
            //var model = getById(id);
            //db.GetTable<ProductEntity>().InsertOnSubmit(model);
            //db.SubmitChanges();
            dm.save(product);
        }
    }
}
